<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
        <el-form-item label="部门" prop="deptId">
          <treeselect v-model="queryParams.deptId" :options="deptOptions" :show-count="true" placeholder="请选择部门"
            style="width: 550px"/>
        </el-form-item>
        <el-form-item label="仓库" prop="storeId">
          <treeselect v-model="queryParams.storeId" :options="storeOptions" :show-count="true" placeholder="请选择仓库"
            style="width: 550px"/>
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select v-model="queryParams.type" placeholder="请选择类型" clearable size="small">
            <el-option v-for="dict in dict.type.oms_task_type" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单编号" prop="taskNo">
          <el-input v-model="queryParams.taskNo" placeholder="请输入订单编号" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <!-- <el-form-item label="仓库" prop="storeId">
      <el-input
        v-model="queryParams.storeId"
        placeholder="请输入仓库"
        clearable
        size="small"
        @keyup.enter.native="handleQuery"
      />
    </el-form-item> -->
        <el-form-item label="状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
            <el-option v-for="dict in dict.type.sys_common_status" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="下单时间" prop="updateTime">
          <el-date-picker clearable size="small" v-model="queryParams.updateTime" type="date"
            value-format="yyyy-MM-dd" placeholder="请选择下单时间">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="联系方式" prop="tel">
      <el-input
        v-model="queryParams.tel"
        placeholder="请输入联系方式"
        clearable
        size="small"
        @keyup.enter.native="handleQuery"
      />
    </el-form-item> -->
        <!-- <el-form-item label="姓名" prop="name">
      <el-input
        v-model="queryParams.name"
        placeholder="请输入姓名"
        clearable
        size="small"
        @keyup.enter.native="handleQuery"
      />
    </el-form-item> -->
        <!-- <el-form-item label="删除标识" prop="delFlag">
      <el-select v-model="queryParams.delFlag" placeholder="请选择删除标识" clearable size="small">
        <el-option
          v-for="dict in dict.type.sys_del_flag"
          :key="dict.value"
          :label="dict.label"
          :value="dict.value"
        />
      </el-select>
    </el-form-item> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['oms:task:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
            v-hasPermi="['oms:task:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['oms:task:remove']">删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
            v-hasPermi="['oms:task:export']">导出</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-s-unfold" size="mini" :disabled="multiple" @click="handleSend"
            v-hasPermi="['oms:task:add']">下发</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="taskList" @selection-change="handleSelectionChange" border stripe>
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column label="订单id" align="center" prop="id" v-if="true"/> -->

        <el-table-column label="申请编号" prop="taskNo" fixed="left" width="130">
          <template slot-scope="scope">
            <el-link type="primary" @click="handleInfo(scope.row)">{{scope.row.taskNo}}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="部门" prop="deptName"  width="280" />
        <el-table-column label="姓名" prop="name"  width="110" />
        <el-table-column label="联系方式" prop="tel"  width="120" />
        <!-- <el-table-column label="地址" align="left" prop="address" width="380" /> -->
        <el-table-column label="仓库" align="center" prop="storeName" width="260"/>
        <el-table-column label="物品数量" align="center" prop="nums" width="80"/>
        <!-- <el-table-column label="物证重量" align="center" prop="weight"/>
        <el-table-column label="物品体积" align="center" prop="volume" /> -->
        <el-table-column label="物流配送" align="center" prop="delivery" width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.oms_delivery_type" :value="scope.row.delivery" />
          </template>
        </el-table-column>
        <el-table-column label="类型" align="center" prop="propertyType" width="100">
           <template slot-scope="scope">
             <dict-tag :options="dict.type.wms_ex_warehouse_type" :value="scope.row.propertyType" />
           </template>
        </el-table-column>

       <!-- <el-table-column label="审批人" align="left" prop="checkerName" width="100" />
        <el-table-column label="审批时间" align="left" prop="checkTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="审批状态" align="center" prop="checkStatus" width="100" /> -->
        <el-table-column label="备注" align="center" prop="remark" width="200"/>

        <el-table-column label="状态" align="center" prop="status" width="80">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_common_status" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="160" fixed="right">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="经度" align="center" prop="lng" />
    <el-table-column label="纬度" align="center" prop="lat" /> -->

        // <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
        //   <template slot-scope="scope">
        //     <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
        //       v-hasPermi="['oms:task:edit']">修改</el-button>
        //     <el-button size="mini" type="text" icon="el-icon-s-unfold" @click="handleSend(scope.row)"
        //       v-hasPermi="['oms:task:add']">下发</el-button>
        //     <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
        //       v-hasPermi="['oms:task:remove']">删除</el-button>
        //   </template>
        // </el-table-column> -->
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    <!-- 添加或修改出入库订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1080px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col>
            <el-form-item label="申请单位" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择申请单位"
                 />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">

          <el-col :span="8">
            <el-form-item label="申请人" prop="name">
              <el-select v-model="form.name" placeholder="请选择申请人" @change="getUserMobile" clearable>
                <el-option v-for="item in contactsOptions" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="tel">
              <el-input v-model="form.tel" placeholder="请输入联系方式" style="width: 220px" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请时间" prop="requestTime">
             <el-date-picker clearable  v-model="form.requestTime" type="date" value-format="yyyy-MM-dd HH:mm:ss"
               placeholder="请选择日期">
             </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15" v-if="form.delivery == '0'">
          <el-col :span="24">
            <el-form-item label="联系地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入联系地址" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="出库类型" prop="propertyType">
              <el-radio-group v-model="form.propertyType">
                <el-radio v-for="dict in dict.type.wms_ex_warehouse_type" v-if="dict.value == 0" :key="dict.value" :label="dict.value">
                  {{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物流配送" prop="delivery">
              <el-radio-group v-model="form.delivery" @change="radioChange">
                <el-radio v-for="dict in dict.type.oms_delivery_type" :key="dict.value" :label="dict.value">
                  {{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物品数量" prop="nums">
              <el-input v-model="form.nums" placeholder="请输入物证重量" style="width: 220px" />
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="15">

          <!-- <el-col :span="8">
            <el-form-item label="物证重量" prop="weight">
              <el-input v-model="form.weight" placeholder="请输入物证重量" style="width: 220px" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物证体积" prop="volume">
              <el-input v-model="form.volume" placeholder="请输入物证体积" style="width: 220px" />
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-row :gutter="15">
          <el-col :span="16">
            <el-form-item label="仓库" prop="storeId">
              <treeselect v-model="form.storeId" :options="storeOptions" :show-count="true" placeholder="请选择仓库" />
            </el-form-item>
          </el-col>

          <!-- <el-col :span="8" v-if="form.propertyType == '2'">
            <el-form-item label="处置方式" prop="dealType">
             <el-select v-model="form.dealType" placeholder="请选择处置方式">
               <el-option v-for="dict in dict.type.wms_deal_type" :key="dict.value" :label="dict.label" :value="dict.value" />
             </el-select>
            </el-form-item>
          </el-col> -->
        </el-row>
        <template>
          <!-- <el-row>
            <el-col :span="8">
              <el-form-item label="归还时间" prop="returnTime">
               <el-date-picker clearable  v-model="form.returnTime" type="date" value-format="yyyy-MM-dd HH:mm:ss"
                 placeholder="请选择日期">
               </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row :gutter="15" >
            <el-col :span="24">
              <el-form-item label="调用原因" prop="dispatchRemark">
                <el-input v-model="form.dispatchRemark" type="textarea" placeholder="请输入内容" />
              </el-form-item>
            </el-col>
          </el-row>
        </template>
        <!-- <template>
          <el-row :gutter="15">
            <el-col :span="8">
              <el-form-item label="收件单位" prop="takeDept">
                <treeselect v-model="form.takeDept" :options="deptOptions" :show-count="true" placeholder="请选择收件单位"
                  style="width: 220px" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="收件人" prop="takeContacts">
                <el-select v-model="form.takeContacts" placeholder="请选择收件人" @change="getTakeUser" clearable>
                  <el-option v-for="item in takeContactsOptions" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系电话" prop="takeTel">
                <el-input v-model="form.takeTel" placeholder="请输入联系方式" style="width: 220px" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15">
            <el-col :span="24">
              <el-form-item label="收件地址" prop="takeAddress">
                <el-input v-model="form.takeAddress" placeholder="请输入收件地址" />
              </el-form-item>
            </el-col>
          </el-row>
        </template> -->
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="出库原因" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :offset="2" :span="22">
            <el-card shadow="hover">
              <div slot="header" class="clearfix">
                <span>财物清单</span>
                <el-button type="text" style="float:right;padding: 3px 0" @click="addDtl">新增</el-button>
              </div>
              <el-table :data="form.items" border stripe>
                <el-table-column label="物品编号" align="center" prop="pno">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入物品编号" v-model="scope.row.pno" />
                  </template>
                </el-table-column>
                <el-table-column label="物品名称" align="center" prop="name">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入物品名称" v-model="scope.row.name" />
                  </template>
                </el-table-column>
                <el-table-column label="所在单位" align="center" prop="deptId">
                  <template slot-scope="scope">
                    <treeselect v-model="scope.row.deptId" :options="deptOptions" :show-count="true" append-to-body
                      placeholder="所在单位" size="small" z-index="9999" />
                  </template>
                </el-table-column>
                <el-table-column label="所在机构" align="center" prop="localId">
                  <template slot-scope="scope">
                    <treeselect v-model="scope.row.localId" :options="deptOptions" :show-count="true" append-to-body
                      placeholder="所在机构" size="small" z-index="9999" />
                  </template>
                </el-table-column>
                <el-table-column label="数量" align="center" prop="nums">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入数量" v-model="scope.row.nums" />
                  </template>
                </el-table-column>
               <!-- <el-table-column label="处置方式" align="center" prop="dealType" v-if="form.propertyType == '2'">
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.dealType" placeholder="请选择处置方式">
                      <el-option v-for="dict in dict.type.wms_deal_type" :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                  </template>
                </el-table-column> -->

                <el-table-column label="操作" align="left">
                  <template slot-scope="scope">
                    <el-row>
                      <el-col>
                        <el-button type="danger" size="mini" @click="dtlDel(scope)" v-if="scope.row.delFlag == '0'">删除
                        </el-button>
                        <el-tag type="info" v-if="scope.row.delFlag == '2'">已删除</el-tag>
                      </el-col>
                    </el-row>
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>
        </el-row>


        <!-- <el-row :gutter="15">
          <el-col :span="8" v-if="form.taskNo">
            <el-form-item label="订单编号" prop="taskNo">
              <el-input v-model="form.taskNo" placeholder="请输入订单编号" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="类型" prop="type">
              <el-select v-model="form.type" placeholder="请选择类型">
                <el-option v-for="dict in dict.type.oms_task_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="仓库" prop="storeId">
              <treeselect v-model="form.storeId" :options="storeOptions" :show-count="true" placeholder="请选择仓库" />
            </el-form-item>
          </el-col>

        </el-row>

        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="部门" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="部门"
                style="width: 160px" size="small" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="name">
              <el-select v-model="form.name" placeholder="请选择联系人" @change="getUserMobile">
                <el-option v-for="item in contactsOptions" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系方式" prop="tel">
              <el-input v-model="form.tel" placeholder="请输入联系方式" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :offset="2" :span="22">
            <el-card shadow="hover">
              <div slot="header" class="clearfix">
                <span>财物清单</span>
                <el-button type="text" style="float:right;padding: 3px 0" @click="addDtl">新增</el-button>
              </div>
              <el-table :data="form.items" border stripe>
                <el-table-column label="物品编号" align="center" prop="pno">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入物品编号" v-model="scope.row.pno" />
                  </template>
                </el-table-column>
                <el-table-column label="物品名称" align="center" prop="name">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入物品名称" v-model="scope.row.name" />
                  </template>
                </el-table-column>
                <el-table-column label="所在单位" align="center" prop="deptId">
                  <template slot-scope="scope">
                    <treeselect v-model="scope.row.deptId" :options="deptOptions" :show-count="true" append-to-body
                      placeholder="所在单位" size="small" z-index="9999" />
                  </template>
                </el-table-column>
                <el-table-column label="所在机构" align="center" prop="localId">
                  <template slot-scope="scope">
                    <treeselect v-model="scope.row.localId" :options="deptOptions" :show-count="true" append-to-body
                      placeholder="所在机构" size="small" z-index="9999" />
                  </template>
                </el-table-column>
                <el-table-column label="数量" align="center" prop="nums">
                  <template slot-scope="scope">
                    <el-input placeholder="请输入数量" v-model="scope.row.nums" />
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="left">
                  <template slot-scope="scope">
                    <el-row>
                      <el-col>
                        <el-button type="danger" size="mini" @click="dtlDel(scope)" v-if="scope.row.delFlag == '0'">删除
                        </el-button>
                        <el-tag type="info" v-if="scope.row.delFlag == '2'">已删除</el-tag>
                      </el-col>
                    </el-row>
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>
        </el-row>
        <el-row :gutter="15" style="margin-top: 15px;">
          <el-col :span="8">
            <el-form-item label="物品数量" prop="nums">
              <el-input v-model="form.nums" placeholder="请输入物品数量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物流配送" prop="delivery">
              <el-radio-group v-model="form.delivery">
                <el-radio v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.value">
                  {{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio v-for="dict in dict.type.sys_common_status" :key="dict.value" :label="dict.value">
                  {{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="审批人" prop="checker">
              <el-select v-model="form.checker" placeholder="请选择审批人">
                <el-option v-for="item in userOptions" :key="item.userId" :label="item.nickName"
                  :value="item.userName" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审批时间" prop="checkTime">
              <el-date-picker clearable size="small" v-model="form.checkTime" type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择审批时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row> -->
      </el-form>
      <selectProperty ref="elDrawer" @handleSelected="handleSelected"></selectProperty>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer title="申请详情" :visible.sync="update" size="70%" :before-close="handleClose">
      <div style="margin:0px 10px 15px 10px;" class="clearfix">
          <span style="font-size: 20px;">{{form.taskNo}}</span>
          <div style="float: right;">
            <el-button type="primary" size="mini" @click="handleUpdate">编辑</el-button>
            <el-button  size="mini" @click="handleSend(form)">下发</el-button>
          </div>
      </div>
      <el-card>
        <el-tabs v-model="activeName">
          <el-tab-pane label="申请详情" name="1">
            <el-card>
              <el-descriptions title="基本信息" :column="3" border>
                <el-descriptions-item label="申请单位">{{form.deptName}}</el-descriptions-item>
                <el-descriptions-item label="申请人">{{form.name}}</el-descriptions-item>
                <el-descriptions-item label="联系电话">{{form.tel}}</el-descriptions-item>
                <el-descriptions-item v-if="form.delivery == '0'" label="寄件地址" :span="3">{{form.address}}</el-descriptions-item>>
                <el-descriptions-item label="出库类型">
                  <dict-tag :options="dict.type.wms_ex_warehouse_type" :value="form.propertyType" />
                </el-descriptions-item>
                <el-descriptions-item label="物流配送">
                  <dict-tag :options="dict.type.oms_delivery_type" :value="form.delivery" />
                </el-descriptions-item>
                <el-descriptions-item label="申请时间">
                  <span>{{ parseTime(form.requestTime, '{y}-{m}-{d}') }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="物品数量">{{form.nums}}</el-descriptions-item>
                <el-descriptions-item label="物品重量">{{form.weight}}</el-descriptions-item>
                <el-descriptions-item label="物品体积">{{form.volume}}</el-descriptions-item>
                <el-descriptions-item label="出库仓库">{{form.storeName}}</el-descriptions-item>
                <el-descriptions-item label="出库原因":span="2">{{form.remark}}</el-descriptions-item>
                <el-descriptions-item label="归还时间">{{form.returnTime}}</el-descriptions-item>
                <el-descriptions-item label="调用原因">{{form.dispatchRemark}}</el-descriptions-item>
              </el-descriptions>
            </el-card>
          </el-tab-pane>
          <el-tab-pane label="财物清单" name="2">
            <el-card shadow="hover" style="margin-top: 10px;">
              <div slot="header" class="clearfix">
                <span>财物清单</span>
              </div>
              <el-table :data="form.items"  border stripe>
                <el-table-column label="物品编号" align="center" prop="pno">
                  <template slot-scope="scope">
                    <span>{{scope.row.pno}}</span>
                  </template>
                </el-table-column>
                <el-table-column label="物品名称" align="center" prop="name">
                  <template slot-scope="scope">
                    <span>{{scope.row.name}}</span>
                  </template>
                </el-table-column>
                <el-table-column label="数量" align="center" prop="nums">
                  <template slot-scope="scope">
                    <span>{{scope.row.nums}}</span>
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-tab-pane>
          <el-tab-pane label="交接信息" name="3" v-if="handoverOptions.length > 0">
            <template v-for="item in handoverOptions">
              <el-collapse>
                <el-collapse-item name="0">
                  <div slot="title">
                   <span style="font-size: 18px;">{{item.type =='0'?'取件交接':'收件交接'}}</span>
                  </div>
                  <el-card>
                    <div slot="header">
                      <span>基本信息</span>
                    </div>
                    <el-descriptions :column="2" border>
                      <el-descriptions-item :label="item.type =='0'?'取件人':'派件人'">{{item.operatorName}}</el-descriptions-item>
                      <el-descriptions-item label="对接人">{{item.counterpartName}}</el-descriptions-item>
                      <el-descriptions-item :label="item.type =='0'?'取件签名':'派件签名'">
                        <el-image
                          style="width: 100px; height: 100px"
                          :src="item.signs"
                          :preview-src-list="[item.signs]">
                        </el-image>
                      </el-descriptions-item>
                      <el-descriptions-item label="对接人签名">
                        <el-image
                          style="width: 100px; height: 100px"
                          :src="item.counterpartSign"
                          :preview-src-list="[item.counterpartSign]">
                        </el-image>
                      </el-descriptions-item>
                      <el-descriptions-item label="交接时间">{{ parseTime(item.handTime, '{y}-{m}-{d}') }}</el-descriptions-item>
                      <el-descriptions-item label="交接备注">{{ item.memo}}</el-descriptions-item>
                      <el-descriptions-item label="交接附件" :span="2">
                        <template  v-if="item.handPics">
                          <el-image v-for="(pic,pindex) in item.handPics.split(',')"
                            style="width: 120px; height: 60px;margin-right: 5px;" :src="pic" fit="scale-down"
                            :preview-src-list="item.handPics.split(',')"></el-image>
                        </template>
                      </el-descriptions-item>
                    </el-descriptions>
                  </el-card>
                  <el-card style="margin-top: 10px;">
                    <div slot="header">
                      <span>交接清单</span>
                    </div>
                    <el-table :data="item.items">
                      <el-table-column label="编号" prop="pno"></el-table-column>
                      <el-table-column label="名称" prop="name"></el-table-column>
                      <el-table-column label="数量" prop="nums"></el-table-column>
                      <el-table-column label="图片" prop="pics">
                        <template slot-scope="scope">
                          <el-image v-for="(pic,pindex) in scope.row.pics.split(',')"
                            style="width: 120px; height: 60px;margin-right: 5px;" :src="pic" fit="scale-down"
                            :preview-src-list="scope.row.pics.split(',')"></el-image>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-card>
                </el-collapse-item>
              </el-collapse>
            </template>
          </el-tab-pane>
          <el-tab-pane label="配送信息" name="4" v-if="orderOptions && checkPermi(['datas:query:tms'])">
             <el-tabs tab-position="left">
                <el-tab-pane label="订单信息">
                  <el-descriptions title="基本信息" :column="3" border>
                    <el-descriptions-item label="订单编号">{{orderOptions.orderNo}}</el-descriptions-item>
                    <el-descriptions-item label="所属部门">{{orderOptions.deptName}}</el-descriptions-item>
                    <el-descriptions-item label="客户名称">{{orderOptions.clientName}}</el-descriptions-item>
                    <el-descriptions-item label="联系人">{{orderOptions.clientContacts}}</el-descriptions-item>
                    <el-descriptions-item label="联系电话">{{orderOptions.clientTel}}</el-descriptions-item>
                    <el-descriptions-item label="备注">{{orderOptions.memo}}</el-descriptions-item>
                    <el-descriptions-item label="物品数量">{{orderOptions.nums}}</el-descriptions-item>
                    <el-descriptions-item label="物品重量">{{orderOptions.weight}}</el-descriptions-item>
                    <el-descriptions-item label="物品体积">{{orderOptions.volume}}</el-descriptions-item>
                  </el-descriptions>
                  <el-descriptions title="寄收地址" :column="3" border style="margin-top: 15px;">
                    <el-descriptions-item label="寄件单位">{{orderOptions.sendAddr}}</el-descriptions-item>
                    <el-descriptions-item label="寄件联系人">{{orderOptions.sendContacts}}</el-descriptions-item>
                    <el-descriptions-item label="联系方式">{{orderOptions.sendTel}}</el-descriptions-item>
                    <el-descriptions-item label="寄件地址" :span="3">{{orderOptions.sendAddress}}</el-descriptions-item>
                    <el-descriptions-item label="收件单位">{{orderOptions.takeAddr}}</el-descriptions-item>
                    <el-descriptions-item label="收件联系人">{{orderOptions.takeContacts}}</el-descriptions-item>
                    <el-descriptions-item label="联系方式">{{orderOptions.takeTel}}</el-descriptions-item>
                    <el-descriptions-item label="收件地址" :span="3">{{orderOptions.takeAddress}}</el-descriptions-item>
                  </el-descriptions>
                  <el-card style="margin-top: 15px;">
                    <div slot="header" class="clearfix">
                      <span style="font-weight: bold;">物品清单</span>
                    </div>
                    <el-table :data="orderOptions.items">
                      <el-table-column label="编号" prop="pno" />
                      <el-table-column label="名称" prop="name" />
                      <el-table-column label="数量" prop="nums" />
                    </el-table>
                  </el-card>
                </el-tab-pane>
                <el-tab-pane label="运单信息">
                  <template v-for="item in orderOptions.wayItems">
                    <el-collapse>
                      <el-collapse-item :title="item.waybillNo">
                        <el-descriptions :column="3" border>
                          <el-descriptions-item label="运单编号">{{item.waybillNo}}</el-descriptions-item>
                          <el-descriptions-item label="线路">{{item.lineName}}</el-descriptions-item>
                          <el-descriptions-item label="车次">{{item.scheduleName}}</el-descriptions-item>
                          <el-descriptions-item label="车牌号">{{item.carNumber}}</el-descriptions-item>
                          <el-descriptions-item label="司机" :span="2">{{item.driverName}}</el-descriptions-item>
                          <el-descriptions-item label="物品数量">{{item.nums}}</el-descriptions-item>
                          <el-descriptions-item label="物品重量">{{item.weight}}</el-descriptions-item>
                          <el-descriptions-item label="物品体积">{{item.volume}}</el-descriptions-item>
                        </el-descriptions>
                        <el-card style="margin-top: 15px;">
                          <div slot="header" class="clearfix">
                            <span style="font-weight: bold;">物品清单</span>
                          </div>
                          <el-table :data="item.items">
                            <el-table-column label="编号" prop="pno" />
                            <el-table-column label="名称" prop="name" />
                            <el-table-column label="数量" prop="nums" />
                          </el-table>
                        </el-card>
                        <el-card style="margin-top: 15px;">
                          <div slot="header" class="clearfix">
                            <span style="font-weight: bold;">日志跟踪</span>
                          </div>
                          <el-table :data="item.logItems">
                            <el-table-column label="操作人" prop="operator" />
                            <el-table-column label="节点名称">
                              <template slot-scope="scope">
                                <dict-tag :options="dict.type.tms_track_log_type" :value="scope.row.type" />
                              </template>
                            </el-table-column>
                            <el-table-column label="操作时间" prop="createTime"></el-table-column>
                            <el-table-column label="备注" prop="memeo" />
                          </el-table>
                        </el-card>
                      </el-collapse-item>
                    </el-collapse>
                  </template>
                </el-tab-pane>
              </el-tabs>
          </el-tab-pane>
          <el-tab-pane label="挑拣任务" name="5" v-if="pickOptions && checkPermi(['datas:query:wms'])">
            <el-descriptions title="基本信息" :column="3" border style="margin-top: 15px;">
             <el-descriptions-item label="任务编号">{{pickOptions.pickNo}}</el-descriptions-item>
             <el-descriptions-item label="挑拣员">{{pickOptions.nickName}}</el-descriptions-item>
             <el-descriptions-item label="状态">
               <dict-tag :options="dict.type.wms_pick_task_status" :value="pickOptions.status" />
             </el-descriptions-item>
            </el-descriptions>
            <el-card style="margin-top: 15px;">
              <div slot="header" class="clearfix">
                <span>物品清单</span>
              </div>
              <el-table :data="pickOptions.items">
                <el-table-column label="编号" prop="pno" />
                <el-table-column label="名称" prop="name" />
                <el-table-column label="数量" prop="nums" />
                <el-table-column label="状态" prop="nums">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.wms_pick_task_status" :value="scope.row.status" />
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-tab-pane>
          <el-tab-pane label="操作日志" name="6">
            <el-table :data="logOptions">
              <el-table-column label="操作人" prop="operator" />
              <el-table-column label="操作时间" prop="logTime" />
              <el-table-column label="动作" prop="content" />
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </el-card>

    </el-drawer>
  </div>
</template>

<script>
  import {
    listTask,
    getTask,
    delTask,
    addTask,
    updateTask
  } from "@/api/oms/task";
  import {
    listStore,
    storeTreeselect
  } from "@/api/wms/store";
  import {
    contacts
  } from "@/api/oms/contacts";
  import {
    treeselect
  } from "@/api/system/dept";
  import {
    listUser
  } from "@/api/system/user";
  import {
    sendsTask
  } from "@/api/center/index";
  import {listOperatorLog} from "@/api/oms/operatorLog"
 import {listHandover} from '@/api/wms/handover'
  import {getOrderTask} from '@/api/tms/order'
  import {getPickTask} from '@/api/wms/pick'
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import selectProperty from "@/components/SelectProperty/index.vue";
  export default {
    name: "Task",
    dicts: ['sys_common_status', 'sys_del_flag', 'oms_task_type', 'oms_delivery_type','wms_ex_warehouse_type','wms_deal_type'],
    components: {
      Treeselect,
      selectProperty
    },
    data() {
      return {
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 出入库订单表格数据
        taskList: [],
        storeOptions: [],
        storeTree: [],
        storeName: undefined,
        deptOptions: [],
        userOptions: [],
        contactsOptions: [],
        takeContactsOptions:[],
        handoverOptions:[],
        logOptions:[],
        orderOptions:{},
        pickOptions:{},
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        update:false,
        activeName:'1',
        defaultProps: {
          children: "children",
          label: "label"
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          taskNo: undefined,
          type: '3',
          storeId: undefined,
          checkStatus: undefined,
          deptId: undefined,
          status: undefined,
          updateTime: undefined,
          tel: undefined,
          name: undefined,
          delFlag: undefined,
          propertyType:'0'
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          deptId: [{
            required: true,
            message: "寄件单位不能为空",
            trigger: "blur"
          }],
          name: [{
            required: true,
            message: "寄件人不能为空",
            trigger: "blur"
          }],
          tel: [{
            required: true,
            message: "联系方式不能为空",
            trigger: "blur"
          }],
          address: [{
            required: true,
            message: "地址不能为空",
            trigger: "blur"
          }],
          propertyType: [{
            required: true,
            message: "物证类型不能为空",
            trigger: "blur"
          }],
          delivery: [{
            required: true,
            message: "物流配送不能为空",
            trigger: "blur"
          }],
          // returnTime:[{
          //   required: true,
          //     message: "归还时间不能为空",
          //     trigger: "blur"
          // }],
          dispatchRemark:[{
            required: true,
              message: "调用原因不能为空",
              trigger: "blur"
          }],
          takeDept:[{
            required: true,
              message: "收件单位不能为空",
              trigger: "blur"
          }],
          takeContacts:[{
            required: true,
              message: "收件人不能为空",
              trigger: "blur"
          }],
          takeTel:[{
            required: true,
              message: "收件联系方式不能为空",
              trigger: "blur"
          }],
          takeAddress:[{
            required: true,
              message: "收件地址不能为空",
              trigger: "blur"
          }],
          dealType:[{
            required: true,
              message: "处置方式不能为空",
              trigger: "blur"
          }]
        }
      };
    },
    watch: {
      storeName(val) {
        this.$refs.tree.filter(val);
      },
      'queryParams.deptId': {
        handler(newVal, oldVal) {
          this.deptChange();
        },
        deep: true,
        immediate: true
      },
      'form.deptId': {
        handler(newVal, oldVal) {
          this.selectDeptId()
        }
      },
      'form.takeDept': {
        handler(newVal, oldVal) {
          this.selectTakeDept()
        }
      }
    },
    created() {
      this.getList();
      this.getStoreTreeselect();
      this.getTreeselect();
    },
    methods: {
      /** 查询出入库订单列表 */
      getList() {
        this.loading = true;
        listTask(this.queryParams).then(response => {
          this.taskList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getLogs(id){
        listOperatorLog({"objid":id}).then(response=>{
          this.logOptions = response.rows;
        })
      },
      /** 查询分类下拉树结构 */
      getStoreTreeselect() {
        storeTreeselect().then(response => {
          this.storeOptions = response.data;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      getUsers() {
        listUser({
          'deptId': this.form.deptId
        }).then(response => {
          this.userOptions = response.rows
        })
      },
      getUserMobile(e) {

        let _this = this;
        this.contactsOptions.forEach(item => {
          if (item.id == e) {
            _this.form.name = item.name;
            _this.form.tel = item.tel;

            _this.form.lng = item.lng;
            _this.form.lat = item.lat;
            if(_this.form.delivery == '0'){
              _this.form.address = item.address;
            }
          }
        });
      },
      getTakeUser(e){
        let _this = this;
        this.takeContactsOptions.forEach(item => {
          if (item.id == e) {
            _this.form.takeContacts = item.name;
            _this.form.takeTel = item.tel;
            _this.form.takeLng = item.lng;
            _this.form.takeLat = item.lat;
            _this.form.takeAddress = item.address;
          }
        });
      },
      radioChange(e){
        this.form.address = undefined;
      },
      getContacts() {
        contacts({
          'deptId': this.form.deptId
        }).then(response => {
          this.contactsOptions = response.data
        })
      },
      getTakeContacts() {
        contacts({
          'deptId': this.form.takeDept
        }).then(response => {
          this.takeContactsOptions = response.data
        })
      },
      deptChange() {
        this.getList();
      },
      selectDeptId() {
        this.getUsers();
        this.getContacts();
      },
      selectTakeDept() {
        this.getTakeContacts();
      },
      // 筛选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleNodeClick(data) {
        this.queryParams.storeId = data.id;
        this.form.storeId = data.id;
        this.handleQuery();
      },
      normalizer(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.id,
          label: node.name,
          children: node.children
        };
      },
      // 取消按钮
      cancel() {
        this.open = false;
        // this.reset();
      },
      handleClose(){
        this.update = false;
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          taskNo: undefined,
          type: '3',
          storeId: undefined,
          nums: 0,
          weight:0,
          volume:0,
          checker: undefined,
          checkTime: undefined,
          checkStatus: "0",
          remark: undefined,
          delivery: '0',
          deptId: undefined,
          status: '0',
          createTime: undefined,
          createBy: undefined,
          updateTime: undefined,
          updateBy: undefined,
          lng: undefined,
          lat: undefined,
          address: undefined,
          tel: undefined,
          name: undefined,
          delFlag: '0',
          items: [],
          propertyType:'0'
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      getHandover(id){
        listHandover({'objid':id}).then(response=>{
          this.handoverOptions = response.rows;
        })
      },
      getOrderInfo(id){
        getOrderTask(id).then(response=>{
          this.orderOptions = response.data;
        })
      },
      getPickInfo(id){
        getPickTask(id).then(response=>{
          this.pickOptions = response.data;
        })
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加调用申请";
        this.form.storeId = this.queryParams.storeId
        this.getContacts()
        this.getTakeContacts()
        // this.$refs.elDrawer.getList()
        this.getConfigKey("sys.wms.issued").then(response => {
          if(response.msg == 'true'){
            this.issued = true;
          }else if(response.msg == 'false'){
            this.issued = false;
          }
        });
      },
      handleInfo(row) {
        this.update = true;
        this.reset();
         const id = row.id || this.ids
         this.getInfo(id);
         this.getOrderInfo(id);
         this.getPickInfo(id);
         this.loading = false;
         this.getHandover(id);
         this.getLogs(id);
      },
      getInfo(id){
        getTask(id).then(response => {
          this.form = response.data;
        });
      },

      handleUpdate(row) {
        // this.loading = true;
        // this.reset();
        // const id = row.id || this.ids
        // getTask(id).then(response => {
        //   this.loading = false;
        //   this.form = response.data;
        //   this.open = true;
        //   this.title = "修改出库申请";
        // });
        // this.getContacts();
        // this.$refs.elDrawer.getList()
        this.open = true;
        this.title = "修改调用申请";
        this.$refs.elDrawer.getList();
      },
      addDtl() {
        // let data = {
        //   id: undefined,
        //   taskId: undefined,
        //   pno: undefined,
        //   name: undefined,
        //   deptId: undefined,
        //   localId: undefined,
        //   nums: undefined,
        //   delFlag: '0'
        // }
        // this.form.items.push(data)
        this.$refs.elDrawer.open()
      },
      dtlDel(scope) {
        let index = scope.$index;
        if (this.form.items[index].id && this.form.items[index].id != '') {
          this.form.items[index].delFlag = '2';
        } else {
          this.form.items.splice(index, 1)
        }
      },
      //获取选择后的财务数据
      handleSelected(array) {
        array.forEach(item => {
          item.delFlag = '0'
          item.id = undefined
          this.form.items.push(item)
        })
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updateTask(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addTask(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
              }).finally(() => {
                this.open = false;
                this.getList();
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除出入库订单编号为"' + ids + '"的数据项？').then(() => {
          this.loading = true;
          return delTask(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).finally(() => {
          this.loading = false;
        });
      },
      handleSend(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认下发所选数据项？').then(() => {
          this.loading = true;
          return sendsTask(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("下发成功");
        }).finally(() => {
          this.loading = false;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('oms/task/export', {
          ...this.queryParams
        }, `task_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
